<?php
/*
+--------------------------------------------------------------------------
|   AffiliStore 2
|   ========================================
|   Web: http://www.affilistore.com
|   Email: admin (at) affilistore (dot) com
|	License Type: AffiliStore 2 is NOT open source software and limitations apply 
|   Licence Info: Visit AffiliStore website and click on 'Licence'
+--------------------------------------------------------------------------
*/
// checks to see if password session is set
// if not redirects to ../admin/
if($_SESSION['loggedIn'] == 0 && !isset($adminPage)){
include('../includes/auth.inc.php');
}


// include fck wysiwyg editor
include("includes/rte/fckeditor.php");

// add a category
if (isset($_POST['cd_updated'])) {

	// check to see if details have been completed
	if (empty($_POST['addThisCategory'])) {
	$error = 1;

	// insert new category
	} else {
	
		if ($_POST['addPriceLim'] == NULL) {
		$addPriceLim = 9999999999.99;
		}
		
		if ($_POST['parentCategory'] == 'noparent') {
			if ($_POST['newLinkGroupSelect'] == NULL) {
			$linkGroup = $_POST['linkGroupSelect'];
			} else {
			$linkGroup = $_POST['newLinkGroupSelect'];
			}
		} else {
		$getParentLinkgroup = mysql_query("SELECT linkGroup FROM affiliSt_categories WHERE id = ".$_POST['parentCategory']."");
		$parentLinkgroup = mysql_fetch_assoc($getParentLinkgroup);
		$linkGroup = $parentLinkgroup['linkGroup'];
		}

	$sql =  sprintf("INSERT INTO affiliSt_categories (name, parent, keywords, negkeywords, searchType, priceFrom, bindParent, priceLimit, searchCols, negSearchCols, linkGroup, subLinks, content) values (%s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s, %s)",
			   quote_smart($_POST['addThisCategory']),
			   quote_smart($_POST['parentCategory']),
			   quote_smart($_POST['addKeywords']),
			   quote_smart($_POST['addNegKeywords']),
			   quote_smart($_POST['cat_andor']),
			   quote_smart($_POST['addPriceFrom']),
			   quote_smart($_POST['parentBind']),
			   quote_smart($addPriceLim),
			   quote_smart($_POST['searchCols0'].':'.$_POST['searchCols1'].':'.$_POST['searchCols2'].':'.$_POST['searchCols3'].':'.$_POST['searchCols4'].':'.$_POST['searchCols5'].':'.$_POST['searchCols6'].':'.$_POST['searchCols7'].':'.$_POST['searchCols8'].':'.$_POST['searchCols9'].':'.$_POST['searchCols10'].':'.$_POST['searchCols11']),
			   quote_smart($_POST['negSearchCols0'].':'.$_POST['negSearchCols1'].':'.$_POST['negSearchCols2'].':'.$_POST['negSearchCols3'].':'.$_POST['negSearchCols4'].':'.$_POST['negSearchCols5'].':'.$_POST['negSearchCols6'].':'.$_POST['negSearchCols7'].':'.$_POST['negSearchCols8'].':'.$_POST['negSearchCols9'].':'.$_POST['negSearchCols10'].':'.$_POST['negSearchCols11']),
			   quote_smart($linkGroup),
			   quote_smart($_POST['linksSub']),
			   quote_smart($_POST['addContent']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		// add one to parent subCategories counter
		if ($_POST['parentCategory'] != 'noparent') {
		$sql =  sprintf("UPDATE affiliSt_categories SET subCategories = subCategories + 1 WHERE id = %s",
				   quote_smart($_POST['parentCategory']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		}
	
	}
}


// delete a category
if (isset($_GET['delete'])) {
$sql =  sprintf("DELETE FROM affiliSt_categories WHERE id = %s",
           quote_smart($_GET['delete']));
mysql_query($sql, $databaseConnect) or die(mysql_error());

	// subtract one from parent subCategories counter
	if (isset($_GET['p'])) {
	$sql =  sprintf("UPDATE affiliSt_categories SET subCategories = subCategories - 1 WHERE id = %s",
				quote_smart($_GET['p']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
	}
}


// edit a category
if (isset($_POST['cd_edited'])) {

	// check to see if details have been completed
	if (empty($_POST['editThisCategory'])) {
	$error = 1;

	// insert new category
	} else {
	
		if ($_POST['addPriceLim'] == NULL) {
		$addPriceLim = 999999999.99;
		}
		
		if ($_POST['parentCategory'] == 'noparent') {
			if ($_POST['newLinkGroupSelect'] == NULL) {
			$linkGroup = $_POST['linkGroupSelect'];
			} else {
			$linkGroup = $_POST['newLinkGroupSelect'];
			}
		} else {
		$getParentLinkgroup = mysql_query("SELECT linkGroup FROM affiliSt_categories WHERE id = ".$_POST['parentCategory']."");
		$parentLinkgroup = mysql_fetch_assoc($getParentLinkgroup);
		$linkGroup = $parentLinkgroup['linkGroup'];
		}
		
		// update child link groups
		$getChildLinks = mysql_query("SELECT subCategories FROM affiliSt_categories WHERE id = ".$_POST['editID']."");
		$childLinks = mysql_fetch_assoc($getChildLinks);
		if ($childLinks['subCategories'] != 0) {
		$sql =  sprintf("UPDATE affiliSt_categories SET linkGroup = %s WHERE parent = %s",
			   quote_smart($linkGroup),
			   quote_smart($_POST['editID']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		}
		

	$sql =  sprintf("UPDATE affiliSt_categories SET name = %s, parent = %s, keywords = %s, negkeywords = %s, searchType = %s, priceFrom = %s, priceLimit = %s, bindParent = %s, searchCols = %s, negSearchCols = %s, linkGroup = %s, subLinks = %s, content = %s WHERE id = %s",
			   quote_smart($_POST['editThisCategory']),
			   quote_smart($_POST['parentCategory']),
			   quote_smart($_POST['addKeywords']),
			   quote_smart($_POST['addNegKeywords']),
			   quote_smart($_POST['cat_andor']),
			   quote_smart($_POST['addPriceFrom']),
			   quote_smart($addPriceLim),
			   quote_smart($_POST['parentBind']),
			   quote_smart($_POST['searchCols0'].':'.$_POST['searchCols1'].':'.$_POST['searchCols2'].':'.$_POST['searchCols3'].':'.$_POST['searchCols4'].':'.$_POST['searchCols5'].':'.$_POST['searchCols6'].':'.$_POST['searchCols7'].':'.$_POST['searchCols8'].':'.$_POST['searchCols9'].':'.$_POST['searchCols10'].':'.$_POST['searchCols11']),
			   quote_smart($_POST['negSearchCols0'].':'.$_POST['negSearchCols1'].':'.$_POST['negSearchCols2'].':'.$_POST['negSearchCols3'].':'.$_POST['negSearchCols4'].':'.$_POST['negSearchCols5'].':'.$_POST['negSearchCols6'].':'.$_POST['negSearchCols7'].':'.$_POST['negSearchCols8'].':'.$_POST['negSearchCols9'].':'.$_POST['negSearchCols10'].':'.$_POST['negSearchCols11']),
			   quote_smart($linkGroup),
			   quote_smart($_POST['linksSub']),
			   quote_smart($_POST['editContent']),
			   quote_smart($_POST['editID']));
	mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		if ($_POST['parentCategory'] != 'noparent' && $_POST['parentCategory'] != $_POST['oldParent']) {
		
		// add new
		$sql =  sprintf("UPDATE affiliSt_categories SET subCategories = subCategories + 1 WHERE id = %s",
					quote_smart($_POST['parentCategory']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_categories SET subCategories = subCategories - 1 WHERE id = %s",
					quote_smart($_POST['oldParent']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		} else if  ($_POST['parentCategory'] == 'noparent') {
		
		// minus old
		$sql =  sprintf("UPDATE affiliSt_categories SET subCategories = subCategories - 1 WHERE id = %s",
					quote_smart($_POST['oldParent']));
		mysql_query($sql, $databaseConnect) or die(mysql_error());
		
		}
	
	}
}

$getGroupNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY linkGroup ASC");
$groupNames = mysql_fetch_assoc($getGroupNames);

$getListGroupNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY linkGroup ASC");
$listGroupNames = mysql_fetch_assoc($getListGroupNames);

$getOptGroupNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY linkGroup ASC");
$optGroupNames = mysql_fetch_assoc($getOptGroupNames);
?>

<script type="text/javascript">
function disableStuff(formselect) {
	if (formselect.selectedIndex == 0) {
	document.getElementById('linkGroup').disabled = false;
	document.getElementById('newLinkGroup').disabled = false;
	document.getElementById('subLinks').disabled = false;
	} else {
	document.getElementById('linkGroup').disabled = true;
	document.getElementById('newLinkGroup').disabled = true;
	document.getElementById('subLinks').disabled = true;
	}
}
function selectAllBoxes(formselect, checkgroup, totalboxes) {
	if (formselect.checked == true) {
		for (i=0;i<totalboxes;i++) {
		document.getElementById(checkgroup+i).checked = true;
		}
	} else {
		for (i=0;i<totalboxes;i++) {
		document.getElementById(checkgroup+i).checked = false;
		}
	}
}
</script>

<?php
// error report
if ($error == 1) {
echo '<fieldset><strong style="color:red">ERROR: Fields must not be empty</strong></fieldset>';
} else {
	// category added report
	if (isset($_POST['cd_updated'])) {
	echo '<fieldset><strong style="color:green">Category Added</strong></fieldset>';
	} 
	
	// category edited report
	if (isset($_POST['cd_edited'])) {
	echo '<fieldset><strong style="color:green">Category Edited</strong></fieldset>';
	}
}

?>






<?php
// edit category html
if (isset($_GET['edit'])) {


$sql =  sprintf("SELECT * FROM affiliSt_categories WHERE id = %s",
           quote_smart($_GET['edit']));
$getEditCat = mysql_query($sql, $databaseConnect) or die(mysql_error());
$editCat = mysql_fetch_assoc($getEditCat);
$searchCols = explode(":", $editCat['searchCols']);
$negSearchCols = explode(":", $editCat['negSearchCols']);
?>

<fieldset style="border: 1px solid green;">
<legend>Edit Category</legend>
<form action="index.php?ad=cd" method="post" name="editDetails">
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td valign="top" align="left">
<label for="editThisCat">Category Name: </label>
</td>
<td valign="top" align="left">
<input name="editThisCategory" type="text" id="editThisCat" value="<?php echo $editCat['name'] ?>" class="adminInput" />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="parentCat">Parent Category: </label>
</td>
<td valign="top" align="left">
<select name="parentCategory" id="parentCat" onchange="disableStuff(this);">
<option value="noparent">No Parent</option>
<?php 
// get link groups
do {
	$optresult = $optGroupNames['linkGroup'];
		if ($storedOptCategory != $optresult && $optresult != NULL && $editCat['subCategories'] == 0) {
		echo '<optgroup label="'.$optGroupNames['linkGroup'].'">';
		$getCatNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY name ASC");
		$catNames = mysql_fetch_assoc($getCatNames);

			// repeat cat names options
			do { 
				if ($catNames['id'] !== NULL && $catNames['parent'] == 0 && $editCat['subCategories'] == 0 && $editCat['id'] != $catNames['id'] && $catNames['linkGroup'] == $optGroupNames['linkGroup']) { ?>
				<option value="<?php echo $catNames['id'] ?>"
				<?php if ($editCat['parent'] == $catNames['id']) {
				echo ' selected="selected" ';
				}
				?>
				><?php echo $catNames['name'] ?></option>
			<?php }
			} while ($catNames = mysql_fetch_assoc($getCatNames));
			
		echo '</optgroup>';
		$storedOptCategory = $optresult;
		} else {
		$optresult = $optGroupNames['linkGroup'];
		}
} while ($optGroupNames = mysql_fetch_assoc($getOptGroupNames));			
?>
</select>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="bindParent">Bind Search to Parent Results:</label>
</td>
<td valign="top" align="left">
<input name="parentBind" id="bindParent" type="checkbox" value="1" <?php if ($editCat['bindParent'] == 1) {
	echo ' checked="checked" ';
	}
	?> />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="subLinks">Display Random Sub-Links:</label>
</td>
<td valign="top" align="left">
<input name="linksSub" id="subLinks" type="checkbox" value="1" <?php if ($editCat['subLinks'] == 1) { echo ' checked="checked" '; }
if ($editCat['parent'] != 0) { echo 'disabled="disabled"'; } 
?> />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="linkGroup">Choose Link Group: </label>
</td>
<td valign="top" align="left">
<select name="linkGroupSelect" id="linkGroup" <?php if ($editCat['parent'] != 0) { echo 'disabled="disabled"'; } ?>>
<option value="None" <?php if ($editCat['linkGroup'] == 'None') { echo 'selected="selected"'; } ?> >None</option>
<?php 
do {
	if ($groupNames['linkGroup'] != 'None') {
	$theresult = $groupNames['linkGroup'];
		if ($storedCategory != $theresult && $theresult != NULL) { ?>
		<option value="<?php echo $groupNames['linkGroup'] ?>" <?php if ($editCat['linkGroup'] == $groupNames['linkGroup']) { echo 'selected="selected"'; } ?> ><?php echo $groupNames['linkGroup'] ?></option>
		<?php
		$storedCategory = $theresult;
		} else {
		$theresult = $groupNames['linkGroup'];
		}
	}
} while ($groupNames = mysql_fetch_assoc($getGroupNames));
?>
</select>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="newLinkGroup">New Link Group: </label>
</td>
<td valign="top" align="left">
<input name="newLinkGroupSelect" type="text" class="adminInput" id="newLinkGroup" <?php if ($editCat['parent'] != 0) { echo 'disabled="disabled"'; } ?> />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catKeywords">Keywords to Search:</label>
</td>
<td valign="top" align="left">
<input name="addKeywords" type="text" value="<?php echo $editCat['keywords'] ?>" class="adminInput" id="catKeywords" /><br />
(eg. keyword1,keyword2,keyword3 etc. separated by commas with no space)<br  /><br  />
	<table cellpadding="2" cellspacing="0" border="0" summary="Columns to Search" width="100%">
	<thead>Columns to Search:</thead>
		<tr>
		<td align="left" valign="top">
		<input name="searchCols0" id="search-cols0" type="checkbox" value="1" <?php if ($searchCols[0] == 1) { echo 'checked="checked"'; } ?> /> Merchant<br />
		<input name="searchCols1" id="search-cols1" type="checkbox" value="1" <?php if ($searchCols[1] == 1) { echo 'checked="checked"'; } ?> /> Merchant Product ID<br />
		<input name="searchCols2" id="search-cols2" type="checkbox" value="1" <?php if ($searchCols[2] == 1) { echo 'checked="checked"'; } ?> /> Product Name<br />
		<input name="searchCols3" id="search-cols3" type="checkbox" value="1" <?php if ($searchCols[3] == 1) { echo 'checked="checked"'; } ?> /> Product Brand<br />
		</td>
		<td align="left" valign="top">
		<input name="searchCols4" id="search-cols4" type="checkbox" value="1" <?php if ($searchCols[4] == 1) { echo 'checked="checked"'; } ?> /> Product Category<br />
		<input name="searchCols5" id="search-cols5" type="checkbox" value="1" <?php if ($searchCols[5] == 1) { echo 'checked="checked"'; } ?> /> Product Description<br />
		<input name="searchCols6" id="search-cols6" type="checkbox" value="1" <?php if ($searchCols[6] == 1) { echo 'checked="checked"'; } ?> /> Promotional Text<br />
		<input name="searchCols7" id="search-cols7" type="checkbox" value="1" <?php if ($searchCols[7] == 1) { echo 'checked="checked"'; } ?> /> Extra Field A<br />
		</td>
		<td align="left" valign="top">
		<input name="searchCols8" id="search-cols8" type="checkbox" value="1" <?php if ($searchCols[8] == 1) { echo 'checked="checked"'; } ?> /> Extra Field B<br />
		<input name="searchCols9" id="search-cols9" type="checkbox" value="1" <?php if ($searchCols[9] == 1) { echo 'checked="checked"'; } ?> /> Extra Field C<br />
		<input name="searchCols10" id="search-cols10" type="checkbox" value="1" <?php if ($searchCols[10] == 1) { echo 'checked="checked"'; } ?> /> Extra Field D<br />
		<input name="searchCols11" id="search-cols11" type="checkbox" value="1" <?php if ($searchCols[11] == 1) { echo 'checked="checked"'; } ?> /> Extra Field E<br />
		</td>
		</tr>
		<tr>
		<td colspan="3" align="left" valign="top">
		<input name="selectAll" type="checkbox" onclick="selectAllBoxes(this, 'search-cols', 12);" /> Select/Unselect All
		</td>
		</tr>
	</table>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catNegKeywords">Negative Keywords:</label>
</td>
<td valign="top" align="left">
<input name="addNegKeywords" type="text" value="<?php echo $editCat['negkeywords'] ?>" class="adminInput" id="catNegKeywords" /><br />
(eg. keyword1,keyword2,keyword3 etc. separated by commas with no space)<br  /><br  />
	<table cellpadding="2" cellspacing="0" border="0" summary="Columns to Search" width="100%">
	<thead>Columns to Search:</thead>
		<tr>
		<td align="left" valign="top">
		<input name="negSearchCols0" id="negsearch-cols0" type="checkbox" value="1" <?php if ($negSearchCols[0] == 1) { echo 'checked="checked"'; } ?> /> Merchant<br />
		<input name="negSearchCols1" id="negsearch-cols1" type="checkbox" value="1" <?php if ($negSearchCols[1] == 1) { echo 'checked="checked"'; } ?> /> Merchant Product ID<br />
		<input name="negSearchCols2" id="negsearch-cols2" type="checkbox" value="1" <?php if ($negSearchCols[2] == 1) { echo 'checked="checked"'; } ?> /> Product Name<br />
		<input name="negSearchCols3" id="negsearch-cols3" type="checkbox" value="1" <?php if ($negSearchCols[3] == 1) { echo 'checked="checked"'; } ?> /> Product Brand<br />
		</td>
		<td align="left" valign="top">
		<input name="negSearchCols4" id="negsearch-cols4" type="checkbox" value="1" <?php if ($negSearchCols[4] == 1) { echo 'checked="checked"'; } ?> /> Product Category<br />
		<input name="negSearchCols5" id="negsearch-cols5" type="checkbox" value="1" <?php if ($negSearchCols[5] == 1) { echo 'checked="checked"'; } ?> /> Product Description<br />
		<input name="negSearchCols6" id="negsearch-cols6" type="checkbox" value="1" <?php if ($negSearchCols[6] == 1) { echo 'checked="checked"'; } ?> /> Promotional Text<br />
		<input name="negSearchCols7" id="negsearch-cols7" type="checkbox" value="1" <?php if ($negSearchCols[7] == 1) { echo 'checked="checked"'; } ?> /> Extra Field A<br />
		</td>
		<td align="left" valign="top">
		<input name="negSearchCols8" id="negsearch-cols8" type="checkbox" value="1" <?php if ($negSearchCols[8] == 1) { echo 'checked="checked"'; } ?> /> Extra Field B<br />
		<input name="negSearchCols9" id="negsearch-cols9" type="checkbox" value="1" <?php if ($negSearchCols[9] == 1) { echo 'checked="checked"'; } ?> /> Extra Field C<br />
		<input name="negSearchCols10" id="negsearch-cols10" type="checkbox" value="1" <?php if ($negSearchCols[10] == 1) { echo 'checked="checked"'; } ?> /> Extra Field D<br />
		<input name="negSearchCols11" id="negsearch-cols11" type="checkbox" value="1" <?php if ($negSearchCols[11] == 1) { echo 'checked="checked"'; } ?> /> Extra Field E<br />
		</td>
		</tr>
		<tr>
		<td colspan="3" align="left" valign="top">
		<input name="selectAll" type="checkbox" onclick="selectAllBoxes(this, 'negsearch-cols', 12);" /> Select/Unselect All
		</td>
		</tr>
	</table>
</td>
</tr>
<!--
<tr>
<td>
Type of Search:
</td>
<td>
<label for="catAND">AND</label> <input name="cat_andor" type="radio" value="1" id="catAND" <?php if ($editCat['searchType'] == 0) { echo 'checked="checked"'; } ?> />
<label for="catOR">OR</label> <input name="cat_andor" type="radio" value="0" id="catOR" <?php if ($editCat['searchType'] == 1) { echo 'checked="checked"'; } ?> />
</td>
</tr>
-->
<tr>
<td valign="top" align="left">
<label for="catPriceFrom">Price From:</label>
</td>
<td valign="top" align="left">
<input name="addPriceFrom" type="text" value="<?php echo $editCat['priceFrom']; ?>" class="adminInput" id="catPriceFrom" /><br />
(eg. 10.00)
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catPriceLim">Price Limit:</label>
</td>
<td valign="top" align="left">
<input name="addPriceLim" type="text" value="<?php if ($editCat['priceLimit'] != 999999999.99) { echo $editCat['priceLimit']; } ?>" class="adminInput" id="catPriceLim" /><br />
(eg. 100.00)
</td>
</tr>
<tr>
<td valign="top" align="left" colspan="2">
<?php
$oFCKeditor = new FCKeditor('editContent');
$oFCKeditor->BasePath = 'includes/rte/';
$oFCKeditor->Value = $editCat['content'];
$oFCKeditor->Create();
?>
</td>
</tr>
</table>
<input type="hidden" name="editID" value="<?php echo $_GET['edit']; ?>" />
<input type="hidden" name="oldParent" value="<?php echo $_GET['p']; ?>" />
<input type="hidden" name="cd_edited" value="yes" />
<input value="Edit Category" type="submit" class="padSubmit" />
</form>
</fieldset>













<?php } else { 
// add category html
?>

<fieldset>
<legend>Add Navigation Category</legend>
<form action="index.php?ad=cd" method="post" name="updateDetails">
<table cellpadding="4" cellspacing="0" border="0">
<tr>
<td valign="top" align="left">
<label for="addThisCat">Category Name: </label>
</td>
<td valign="top" align="left">
<input name="addThisCategory" type="text" class="adminInput" id="addThisCat" />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="parentCat">Parent Category: </label>
</td>
<td valign="top" align="left">
<select name="parentCategory" id="parentCat" onchange="disableStuff(this);">
<option value="noparent" selected="selected">No Parent</option>

<?php 
// get link groups
do {
	$optresult = $optGroupNames['linkGroup'];
		if ($storedOptCategory != $optresult && $optresult != NULL) {
		echo '<optgroup label="'.$optGroupNames['linkGroup'].'">';
		$getCatNames = mysql_query("SELECT * FROM affiliSt_categories ORDER BY name ASC");
		$catNames = mysql_fetch_assoc($getCatNames);

			// repeat cat names options
			do { 
				if ($catNames['id'] !== NULL && $catNames['parent'] == 0 && $catNames['linkGroup'] == $optGroupNames['linkGroup']) { ?>
				<option value="<?php echo $catNames['id'] ?>"><?php echo $catNames['name'] ?></option>
			<?php }
			} while ($catNames = mysql_fetch_assoc($getCatNames));
			
		echo '</optgroup>';
		$storedOptCategory = $optresult;
		} else {
		$optresult = $optGroupNames['linkGroup'];
		}
} while ($optGroupNames = mysql_fetch_assoc($getOptGroupNames));
?>
</select>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="bindParent">Bind Search to Parent Results:</label>
</td>
<td valign="top" align="left">
<input name="parentBind" id="bindParent" type="checkbox" value="1" />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="subLinks">Display Random Sub-Links:</label>
</td>
<td valign="top" align="left">
<input name="linksSub" id="subLinks" type="checkbox" value="1" />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="linkGroup">Choose Link Group: </label>
</td>
<td valign="top" align="left">
<select name="linkGroupSelect" id="linkGroup">
<option value="None" selected="selected">None</option>
<?php 
do {
	if ($groupNames['linkGroup'] != 'None') {
	$theresult = $groupNames['linkGroup'];
		if ($storedCategory != $theresult && $theresult != NULL) { ?>
		<option value="<?php echo $groupNames['linkGroup'] ?>"><?php echo $groupNames['linkGroup'] ?></option>
		<?php
		$storedCategory = $theresult;
		} else {
		$theresult = $groupNames['linkGroup'];
		}
	}
} while ($groupNames = mysql_fetch_assoc($getGroupNames));
?>
</select>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="newLinkGroup">New Link Group: </label>
</td>
<td valign="top" align="left">
<input name="newLinkGroupSelect" type="text" class="adminInput" id="newLinkGroup" />
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catKeywords">Keywords to Search:</label>
</td>
<td valign="top" align="left">
<input name="addKeywords" type="text" value="" class="adminInput" id="catKeywords" /><br />
(eg. keyword1,keyword2,keyword3 etc. separated by commas with no space)<br  /><br  />
	<table cellpadding="2" cellspacing="0" border="0" summary="Columns to Search" width="100%">
	<thead>Columns to Search:</thead>
		<tr>
		<td align="left" valign="top">
		<input name="searchCols0" id="search-cols0" type="checkbox" value="1" checked="checked" /> Merchant<br />
		<input name="searchCols1" id="search-cols1" type="checkbox" value="1" checked="checked" /> Merchant Product ID<br />
		<input name="searchCols2" id="search-cols2" type="checkbox" value="1" checked="checked" /> Product Name<br />
		<input name="searchCols3" id="search-cols3" type="checkbox" value="1" checked="checked" /> Product Brand<br />
		</td>
		<td align="left" valign="top">
		<input name="searchCols4" id="search-cols4" type="checkbox" value="1" checked="checked" /> Product Category<br />
		<input name="searchCols5" id="search-cols5" type="checkbox" value="1" checked="checked" /> Product Description<br />
		<input name="searchCols6" id="search-cols6" type="checkbox" value="1" checked="checked" /> Promotional Text<br />
		<input name="searchCols7" id="search-cols7" type="checkbox" value="1" checked="checked" /> Extra Field A<br />
		</td>
		<td align="left" valign="top">
		<input name="searchCols8" id="search-cols8" type="checkbox" value="1" checked="checked" /> Extra Field B<br />
		<input name="searchCols9" id="search-cols9" type="checkbox" value="1" checked="checked" /> Extra Field C<br />
		<input name="searchCols10" id="search-cols10" type="checkbox" value="1" checked="checked" /> Extra Field D<br />
		<input name="searchCols11" id="search-cols11" type="checkbox" value="1" checked="checked" /> Extra Field E<br />
		</td>
		</tr>
		<tr>
		<td colspan="3" align="left" valign="top">
		<input name="selectAll" type="checkbox" onclick="selectAllBoxes(this, 'search-cols', 12);" /> Select/Unselect All
		</td>
		</tr>
	</table>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catNegKeywords">Negative Keywords:</label>
</td>
<td valign="top" align="left">
<input name="addNegKeywords" type="text" value="" class="adminInput" id="catNegKeywords" /><br />
(eg. keyword1,keyword2,keyword3 etc. separated by commas with no space)<br  /><br  />
	<table cellpadding="2" cellspacing="0" border="0" summary="Columns to Search" width="100%">
	<thead>Columns to Search:</thead>
		<tr>
		<td align="left" valign="top">
		<input name="negSearchCols0" id="negsearch-cols0" type="checkbox" value="1" checked="checked" /> Merchant<br />
		<input name="negSearchCols1" id="negsearch-cols1" type="checkbox" value="1" checked="checked" /> Merchant Product ID<br />
		<input name="negSearchCols2" id="negsearch-cols2" type="checkbox" value="1" checked="checked" /> Product Name<br />
		<input name="negSearchCols3" id="negsearch-cols3" type="checkbox" value="1" checked="checked" /> Product Brand<br />
		</td>
		<td align="left" valign="top">
		<input name="negSearchCols4" id="negsearch-cols4" type="checkbox" value="1" checked="checked" /> Product Category<br />
		<input name="negSearchCols5" id="negsearch-cols5" type="checkbox" value="1" checked="checked" /> Product Description<br />
		<input name="negSearchCols6" id="negsearch-cols6" type="checkbox" value="1" checked="checked" /> Promotional Text<br />
		<input name="negSearchCols7" id="negsearch-cols7" type="checkbox" value="1" checked="checked" /> Extra Field A<br />
		</td>
		<td align="left" valign="top">
		<input name="negSearchCols8" id="negsearch-cols8" type="checkbox" value="1" checked="checked" /> Extra Field B<br />
		<input name="negSearchCols9" id="negsearch-cols9" type="checkbox" value="1" checked="checked" /> Extra Field C<br />
		<input name="negSearchCols10" id="negsearch-cols10" type="checkbox" value="1" checked="checked" /> Extra Field D<br />
		<input name="negSearchCols11" id="negsearch-cols11" type="checkbox" value="1" checked="checked" /> Extra Field E<br />
		</td>
		</tr>
		<tr>
		<td colspan="3" align="left" valign="top">
		<input name="selectAll" type="checkbox" onclick="selectAllBoxes(this, 'negsearch-cols', 12);" /> Select/Unselect All
		</td>
		</tr>
	</table>
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catPriceFrom">Price From:</label>
</td>
<td valign="top" align="left">
<input name="addPriceFrom" type="text" value="" class="adminInput" id="catPriceFrom" /><br />
(eg. 10.00)
</td>
</tr>
<tr>
<td valign="top" align="left">
<label for="catPriceLim">Price Limit:</label>
</td>
<td valign="top" align="left">
<input name="addPriceLim" type="text" value="" class="adminInput" id="catPriceLim" /><br />
(eg. 100.00)
</td>
</tr>
<tr>
<td valign="top" align="left" colspan="2">
<?php
$oFCKeditor = new FCKeditor('addContent');
$oFCKeditor->BasePath = 'includes/rte/';
$oFCKeditor->Value = "";
$oFCKeditor->Create();
?>
</td>
</tr>
</table>
<input type="hidden" name="cd_updated" value="yes" />
<input value="Add Category" type="submit" class="padSubmit" />
</form>
</fieldset>

<?php } ?>


<fieldset>
<legend>Current Navigation</legend>

<?php 
// get link groups
do {
	$groupresult = $listGroupNames['linkGroup'];
		if ($storedGroupCategory != $groupresult && $groupresult != NULL) { 
		echo '<p style="font-size:120%; border:1px solid #cccccc; margin:5px 0px 5px 0px; padding:2px; font-weight:bold; background-color:#eeeeee;">Link Group: '.$listGroupNames['linkGroup'].'</p>';
		
		$getTopCat = mysql_query("SELECT * FROM affiliSt_categories ORDER BY name ASC");
		$topCat = mysql_fetch_assoc($getTopCat);

		// repeat category listings
		do { 
			if ($topCat['id'] != NULL && $topCat['parent'] == 0 && $topCat['linkGroup'] == $listGroupNames['linkGroup']) {
			echo '<strong>'.$topCat['name'].'</strong>
			[<a href="index.php?ad=cd&edit='.$topCat['id'].'">edit</a>] ';
				
				// delete if category has no links
				if ($topCat['counter'] == 0 && $topCat['subCategories'] == 0) {
				echo '[<a href="index.php?ad=cd&delete='.$topCat['id'].'">delete</a>]<br />';
				} else {
				echo '[<span style="color:grey">delete</span>]<br />';
				}
		
				$getSubCat = mysql_query("SELECT * FROM affiliSt_categories ORDER BY parent ASC, name ASC");
				$subCat = mysql_fetch_assoc($getSubCat);
			
				// repeat sub category listings
				do { 
					
					if ($subCat['parent'] == $topCat['id']) {
					echo '&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;-&nbsp;'.$subCat['name'].'
					[<a href="index.php?ad=cd&edit='.$subCat['id'].'&p='.$subCat['parent'].'">edit</a>] ';
				
						// delete if category has no links
						if ($subCat['counter'] == 0) {
						echo '[<a href="index.php?ad=cd&delete='.$subCat['id'].'&p='.$subCat['parent'].'">delete</a>]<br />';
						} else {
						echo '[<span style="color:grey">delete</span>]<br />';
						}
					}
				} while ($subCat = mysql_fetch_assoc($getSubCat));
				
			}
		} while ($topCat = mysql_fetch_assoc($getTopCat));
			

		$storedGroupCategory = $groupresult;
		} else {
		$groupresult = $listGroupNames['linkGroup'];
		}
} while ($listGroupNames = mysql_fetch_assoc($getListGroupNames));
?>
</fieldset>